package com.ydd.mapper;

import com.ydd.entity.UserData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@Mapper
public interface UserDataMapper extends BaseMapper<UserData> {

    @Select("select type from ydd_user_data where article_id = #{id} and user_id = #{userId}")
    List<Integer> findType(Integer id, String userId);

    /**
     * 通过type查询到相关的所有文章id
     * @param type
     * @param id
     * @return
     */
    @Select("select article_id from ydd_user_data where type=#{type} and user_id = #{id}")
    List<Integer> findByCondition(Integer type, Integer id);


    @Select("select article_id, user_id, type from ydd_user_data where user_id=#{id}")
    List<UserData> findArticleById(Integer articleid);

    @Update("update ydd_user_data set type = #{type}")
    void updateType(Integer articleid,Integer type);

    /**
     * 获取当前登录用户文章id集合
     * @param userId
     * @return
     */
    @Select("select article_id from youdianda.ydd_user_data where user_id = #{userId}")
    List<Integer> getArticleIds(Integer userId);
}


